package com.xncoding.design.observation.demo1;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * 生产者
 * @author Administrator
 */
public class Producer implements Runnable {
	private String name;
	private final Storage s ;
	private Product product ;
//	private ConcurrentLinkedQueue<Product> workQueue=new ConcurrentLinkedQueue<Product>();
	
	public Producer(Storage s){
		this.s=s;
	}

	@Override
	public void run() {
		int i = 0;
	    try{
	    	while(true){
	    		product = new Product();
	    		product.setId(i);
	    		s.push(product);
	    		System.out.println("生产数据"+i);
	    		Thread.sleep(100);
//	    		if(s.getWorkQueue().isEmpty()){//工作完成
//	    			break;
//	    		}
//	    	    Product product=s.getWorkQueue().poll();
//	    	    if(product==null){
//	    	    	continue;
//	    	    }
	    		i++;
	    	}
		}catch(InterruptedException e1){
			System.out.println(name+":异常");
			
		}finally{
			System.out.println(name+":完成工作");
		}
		

	}
	


}
